package com.aggron.controller;


import com.aggron.bean.PageQuery;
import com.aggron.common.JsonData;
import com.aggron.constants.ControllerConstants;
import com.aggron.params.AclParams;
import com.aggron.service.ISysAclService;
import com.aggron.service.SysTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuhuan
 * @since 2018-06-02
 */
@RestController
@RequestMapping("/sys/acl")
public class SysAclController {

    @Autowired
    private ISysAclService iSysAclService;

    @Autowired
    private SysTreeService sysTreeService;

    @GetMapping("/getAcls")
    public JsonData getUsers(PageQuery pageQuery, AclParams aclParams){
        return JsonData.success(iSysAclService.pageAcl(pageQuery,aclParams));
    }

    @PostMapping("/save")
    public JsonData save(@RequestBody AclParams aclParams){
        iSysAclService.save(aclParams);
        return JsonData.success(ControllerConstants.ADD_SUCCESS_MESSAGE);
    }

    @PostMapping("/update")
    public JsonData update(@RequestBody AclParams aclParams){
        iSysAclService.update(aclParams);
        return JsonData.success(ControllerConstants.UPDATE_SUCCESS_MESSAGE);
    }

    @GetMapping("getMenus")
    public JsonData getMenus(){
        return JsonData.success(sysTreeService.getMenus());
    }

    @PostMapping("/delete")
    public JsonData delete(@RequestBody AclParams aclParams){
        iSysAclService.deleteById(aclParams.getId());
        return JsonData.success(ControllerConstants.DELETE_SUCCESS_MESSAGE);
    }

}

